import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, OneToMany } from 'typeorm';
import { DictData } from './dict-data.entity';
import { TimeTransformer } from 'src/utils/TimeTransformer.util';

/**
 * 字典实体
 */
@Entity('sys_dict')
export class Dict {
  /**
   * 字典ID
   */
  @PrimaryGeneratedColumn({ comment: '字典ID' })
  dictId: number;

  /**
   * 字典名称
   */
  @Column({ comment: '字典名称', length: 100 })
  name: string;

  /**
   * 字典类型
   */
  @Column({ comment: '字典类型', length: 50 })
  type: string;

  /**
   * 状态
   */
  @Column({ comment: '状态', default: true })
  status: boolean;

  /**
   * 备注
   */
  @Column({ comment: '备注', nullable: true, length: 255 })
  remark: string;

  /**
   * 创建时间
   */
  @CreateDateColumn({
    comment: '创建时间',
    transformer: TimeTransformer,
  })
  createTime: Date;

  /**
   * 更新时间
   */
  @UpdateDateColumn({
    comment: '更新时间',
    transformer: TimeTransformer,
  })
  updateTime: Date;

  /**
   * 关联的字典数据
   */
  @OneToMany(() => DictData, (dictData) => dictData.dict)
  dictDatas: DictData[];
}
